package com.scrcu.cloud.wechat.home.endpoint.staff.service.Iml;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scrcu.cloud.wechat.home.endpoint.common.model.RestResponse;
import com.scrcu.cloud.wechat.home.endpoint.customer.entity.BookInfo;
import com.scrcu.cloud.wechat.home.endpoint.customer.entity.Institution;
import com.scrcu.cloud.wechat.home.endpoint.customer.mapper.BookMapper;
import com.scrcu.cloud.wechat.home.endpoint.customer.mapper.InstMapper;
import com.scrcu.cloud.wechat.home.endpoint.customer.vo.BookInfoPlus;
import com.scrcu.cloud.wechat.home.endpoint.customer.vo.BookInfoPlusWithUserInfo;
import com.scrcu.cloud.wechat.home.endpoint.staff.entity.StaffInfo;
import com.scrcu.cloud.wechat.home.endpoint.staff.mapper.StaffInfoMapper;
import com.scrcu.cloud.wechat.home.endpoint.staff.service.IStaffOaService;
import com.scrcu.cloud.wechat.home.endpoint.staff.service.IStaffUserService;
import com.scrcu.cloud.wechat.home.endpoint.staff.utils.Util;
import com.scrcu.cloud.wechat.home.endpoint.staff.vo.StaffInfoPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;


@Service
@Slf4j
public class StaffUserServiceIml implements IStaffUserService {

    @Autowired
    private BookMapper bookMapper;
    @Autowired
    private StaffInfoMapper staffInfoMapper;

    @Override
    public RestResponse getUserList(String staffid) {
        return null;
    }

    @Override
    public RestResponse getBooksByStaff(String staffid,String status) {
        HashMap<String,Object> res = new HashMap<>();
        StaffInfo staffInfo = staffInfoMapper.selectById(staffid);
        if (staffInfo==null)
            return RestResponse.failed("没找到员工信息，请核对");

        ArrayList<BookInfoPlusWithUserInfo> books = bookMapper.getBooksByStaff(staffid,status);

        res.put("books",books);
//        log.info("idcard?>"+books.get(0).getIdcard());
        return RestResponse.success(res);
    }

    @Override
    public RestResponse dealbook(String staffid, String bookid) {
        QueryWrapper<BookInfo> qw = new QueryWrapper<>();
        qw.eq("bookid",bookid).eq("staff_id",staffid).eq("status",99);
        BookInfo book = bookMapper.selectOne(qw);
        book.setStatus(1);
        int uflag = bookMapper.updateById(book);
        if (uflag>=1){
            log.info("更新book成功");
            return RestResponse.success("更新book成功");
        }
        return RestResponse.failed();
    }
}
